package ar.frba.utn.diseñosistemas.Tests.TP1;

import java.text.ParseException;
import java.util.ArrayList;

import junit.framework.Assert;

import ar.frba.utn.diseñosistemas.TP1.*;

import org.junit.Before;
import org.junit.Test;

public class TestFlexibleParser {

	FlexibleParser TodosLosParsers;
	FlexibleParser LatinoamericanoyNorteAmericano;
	FlexibleParser LatinoamericanoyISO;
	FlexibleParser NorteamericanoyISO;
	
	@Before
	public void setUp() throws Exception 
	{
		SimpleParser Latinoamericano = new SimpleParser("dd/MM/yyyy");
		SimpleParser Norteamericano = new SimpleParser("MM-dd-yyyy");
		SimpleParser ISO8601 = new SimpleParser("yyyy-MM-dd");
		
		ArrayList<DateParser> TodosLosParsersList = new ArrayList<DateParser>();
			TodosLosParsersList.add(Norteamericano);
			TodosLosParsersList.add(Latinoamericano);
			TodosLosParsersList.add(ISO8601);
		
		ArrayList<DateParser> LatinoamericanoConNorteAmericanoList = new ArrayList<DateParser>();
			LatinoamericanoConNorteAmericanoList.add(Latinoamericano);
			LatinoamericanoConNorteAmericanoList.add(Norteamericano);
		
		ArrayList<DateParser> LatinoamericanoConISOList = new ArrayList<DateParser>();
			LatinoamericanoConISOList.add(Latinoamericano);
			LatinoamericanoConISOList.add(ISO8601);
		
		ArrayList<DateParser> NorteamericanoConISOList = new ArrayList<DateParser>();
			NorteamericanoConISOList.add(Norteamericano);
			NorteamericanoConISOList.add(ISO8601);
			
		TodosLosParsers = new FlexibleParser(TodosLosParsersList);
		LatinoamericanoyNorteAmericano = new FlexibleParser(LatinoamericanoConNorteAmericanoList);
		LatinoamericanoyISO = new FlexibleParser(LatinoamericanoConISOList);
		NorteamericanoyISO = new FlexibleParser(NorteamericanoConISOList);
	}
	
	@Test
	public void TestParsearISOConTodos() throws Exception
	{
		UnifiedDate aDate = TodosLosParsers.Parse("1989-11-02");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}
	
	@Test
	public void TestParsearLatinoamericanoConTodos() throws Exception
	{
		UnifiedDate aDate = TodosLosParsers.Parse("02/11/1989");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}

	@Test
	public void TestParsearNorteamericanoConTodos() throws Exception
	{
		UnifiedDate aDate = TodosLosParsers.Parse("11-02-1989");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}

	@Test(expected = ParseException.class)
	public void TestParsearISOConLatinoamericanoyNorteAmericano() throws Exception
	{
		LatinoamericanoyNorteAmericano.Parse("1989-11-02");
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearNorteamericanoConLatinoamericanoyISO() throws Exception
	{
		LatinoamericanoyISO.Parse("11-02-1989");
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearLatinoamericanoConNorteamericanoyISO() throws Exception
	{
		NorteamericanoyISO.Parse("02/11/1989");
	}
}
